package com.example.flowerpcback.controller;

import com.example.flowerpcback.dto.Roles;
import com.example.flowerpcback.dto.Tag;
import com.example.flowerpcback.req.RolesReq;
import com.example.flowerpcback.req.TagReq;
import com.example.flowerpcback.resp.CommonResp;
import com.example.flowerpcback.resp.PageResp;
import com.example.flowerpcback.resp.RolesResp;
import com.example.flowerpcback.resp.TagResp;
import com.example.flowerpcback.services.RoleService;
import com.example.flowerpcback.services.TagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "标签接口")
@RestController //这是返回接口
@RequestMapping("/tag")
public class TagController {

    private static final Logger LOG = LoggerFactory.getLogger(TagController.class);

    @Resource
    private TagService tagService;

    @ApiOperation("保存标签（新增或编辑）")
    @PostMapping("/save")
    public CommonResp<TagResp> save(@Valid @RequestBody TagReq req){
        CommonResp resp= new CommonResp<>();
        TagResp tag = tagService.save(req);
        resp.setData(tag);
        return  resp;
    }

    @ApiOperation("标签列表")
    @GetMapping("/list")
    public CommonResp<PageResp<TagResp>> list(@Valid TagReq req){
        CommonResp<PageResp<TagResp>> resp= new CommonResp<>();
        PageResp<TagResp> tagResp = tagService.list(req);
        resp.setData(tagResp);
        return  resp;
    }

    @ApiOperation("所有列表")
    @GetMapping("/all")
    public CommonResp<List<TagResp>> all(@Valid TagReq req){
        CommonResp<List<TagResp>> resp= new CommonResp<>();
        List<TagResp> tagResp = tagService.all(req);
        resp.setData(tagResp);
        return  resp;
    }

    @ApiOperation("删除标签")
    @GetMapping("/delete")
    public CommonResp delete(@Valid TagReq req){
        CommonResp resp= new CommonResp<>();
        tagService.delete(req);
        return  resp;
    }

}

